import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.12
import StatusBar 0.1

ApplicationWindow {
	readonly property string defaultFontFamily: "Noto Sans CJK TC"
	property alias toastItem: toast_displayer
	property alias main_window: main_window
	property alias toolbar_title_label: toolbar_title_label
	property alias mainStackView: main_stackview
	id: main_window
	visible: true
	width: 540
	height: 1140
	title: qsTr("Pure Air")
	flags: Qt.Window | Qt.MaximizeUsingFullscreenGeometryHint
	header: ToolBar {
		z: 5
		topPadding: Qt.platform.os === "ios" ? main_window.height
											   - main_window.desktopAvailableHeight : 0
		contentHeight: drawer_button.implicitHeight
		ColumnLayout {
			anchors.fill: parent
			Rectangle {
				visible: Qt.platform.os === "ios"
				Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
				Layout.fillWidth: true
				height: main_window.height - main_window.desktopAvailableHeight
			}
			RowLayout {
				Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
				Layout.fillHeight: true
				Layout.fillWidth: true
				ToolButton {
					id: drawer_button
					visible: main_stackview.depth > 1 ? true : false
					icon.source: main_stackview.depth > 1 ? "Images/drawable-xxhdpi/baseline_arrow_back_ios_white_48.png" : ""
					icon.color: "white"
					onClicked: {
						if (main_stackview.depth > 1) {
							main_stackview.pop()
							if (main_stackview.depth === 1) {
								toolbar_title_label.text = "室内设置"
							}
						}
					}
				}
				Label {
					id: toolbar_title_label
					verticalAlignment: Text.AlignVCenter
					horizontalAlignment: Text.AlignHCenter
					Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
					Layout.fillWidth: true
					color: "#ffffff"
					text: "室内设置"
					font.family: defaultFontFamily
					font.pointSize: 20
				}
				ToolButton {
					id: menu_button
					visible: main_stackview.depth > 1 ? true : false
					checkable: false
					down: false
					hoverEnabled: false
				}
			}
		}
	}
	StatusBar {
		theme: "Dark"
		color: Material.color(Material.LightGreen, Material.Shade700)
	}
	ToastManager {
		id: toast_displayer
	}

	StackView {
		id: main_stackview
		z: 10
		initialItem: "MainStackView.qml"
		anchors.fill: parent
	}
}
